using System;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using IGlobalist.Cms.Presentation;

namespace IGlobalist.Cms.Presentation
{
    public class BaseCmsPage : Page
    {
        protected ViewController _ViewController;
        protected Literal _RenderContent;

        public PlaceHolder placeHolder;
        protected Hashtable ExtProperties = new Hashtable();
        protected override void OnLoad(EventArgs e)
        {
           //base.OnLoad(e);
            
            long pageID = 0;
            long categoryID = 0;
            long contentID = 0;

            string path = Request.QueryString["path"];          
            try
            {
                pageID = Convert.ToInt64(Request.QueryString["pid"]);
                categoryID = Convert.ToInt64(Request.QueryString["cid"]);
                contentID = Convert.ToInt64(Request.QueryString["ctid"]);
            }
            catch (Exception ex)
            {
                Logger.Error("Convert ID Error.", ex);
                Response.Redirect("~/", true);            
            }
            _ViewController = new ViewController(this, pageID,categoryID, contentID);

            IEnumerator keys= ExtProperties.Keys.GetEnumerator();
            while (keys.MoveNext())
            {
                _ViewController.TemplateEngine.AddToContext(keys.Current.ToString(), ExtProperties[keys.Current]);
            }
            

        }
        protected override void RenderChildren(HtmlTextWriter writer)
        {
            base.RenderChildren(writer);
            _ViewController.Render();
        }

        public log4net.ILog Logger
        {
            get { return log4net.LogManager.GetLogger("File"); }
        }
    }
}
